import DynamicTables from "./index.vue";
import {ComponentOptions,Prop} from "vue";

export type DynamicTable = ComponentOptions<typeof DynamicTables>

export class DyTableUtils {
  /**
   * 返回一个移除联动的函数
   */
  static multipleTableScrollX(dyTables: DynamicTable[]):Function {
    const doms = dyTables.map(i => {
      return i.$refs.tableRef.$refs.scrollBarRef.wrapRef as HTMLElement
    })
    const scroll = (item: HTMLElement) => {
      doms.forEach((i,index) => {
        if (i !== item) {
          i.scrollLeft = item.scrollLeft
        }
      })
    }
    const functions: any[] = []
    doms.forEach((i, index) => {
      functions.push(() => scroll(i))
      i.addEventListener('scroll', functions[index])
    })
    return () => {
      doms.forEach((i, index) => {
        i.removeEventListener('scroll', functions[index])
      })
    }
  }
}
